'use strict';
const BaseService = require('./base');

const StringUtil = require('../utils/StringUtil');
const ResponseUtil = require('../utils/ResponseUtil');

class SysParamService extends BaseService {


    async getSysParam({id}) {
        let sql = `select * from sys_param where id=? `;
        let result = await this.executeSqlFirst(sql, [id]);
        return result;
    }


    async saveSysParam({id, value, remark}) {
        if (!id || !value) {
            return ResponseUtil.retArgErr();
        }

        let loginUserInfo = this.ctx.getLoginInfo();
        let operatorType = loginUserInfo.operatorType;
        let operatorId = loginUserInfo.operatorId;
        let createBy = loginUserInfo.createBy;

        let sql = 'select * from sys_param where id = ?';
        let d = await this.executeSqlFirst(sql, [id]);
        if (d) {
            let sql = 'update sys_param set sysvalue=?,sysname=?,update_by=?,update_by_id=? where id=? ';
            let size = await this.executeSqlSucc(sql, [value, remark, createBy, operatorId, id]);
            return size;
        } else {
            let params = {
                id: id,
                sysvalue: value,
                sysname: remark,
                create_by: createBy,
                create_by_id: operatorId
            };
            return await this.executeInsert('sys_param', params);
        }
    }


}

module.exports = SysParamService;
